package com.bonc.rms.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.bonc.rms.service.UserInfoService;

@RestController
@RequestMapping(value = "/UserInfoController")

public class UserInfoController {
	@Autowired
	UserInfoService userInfoService; 
	
	/*
	 * 查看用户信息
	 */
	@RequestMapping(value = "/getUserInfo")
	@ResponseBody
	public String getUserInfo() {
		List<Map<String, Object>> userInfo = userInfoService.getUserInfo();
		
		return JSON.toJSONString(userInfo);
	}

	/*
	 * 查看单个用户信息
	 */
	@RequestMapping(value = "/getSingleUserInfo")
	@ResponseBody
	public String getSingleUserInfo(@RequestParam(value = "userId") Integer userId) {
		List<Map<String, Object>> userInfo = userInfoService.getSingleUserInfo(userId);
		
		return JSON.toJSONString(userInfo);
	}
	
	/*
	 * 修改用户信息
	 */
	@RequestMapping(value = "/updateUserInfo")
	@ResponseBody
	public String updateUserInfo(@RequestParam(value = "userId") Integer userId,
			@RequestParam(value = "userName") String userName,
			@RequestParam(value = "password") String password,
			@RequestParam(value = "address") String address,
			@RequestParam(value = "email") String email,
			@RequestParam(value = "mobilePhone") String mobilePhone,
			@RequestParam(value = "sex") String sex) {
		
		List<Map<String, Object>> userInfo = userInfoService.updateUserInfo(userId,userName,password,address,email,mobilePhone,sex);
		
		return JSON.toJSONString(userInfo);
	}
	
	/*
	 * 删除用户信息
	 */
	@RequestMapping(value = "/deleteUserInfo")
	@ResponseBody
	public String deleteUserInfo(@RequestParam(value = "userId") Integer userId) {
		
		userInfoService.deleteUserInfo(userId);
		
		Map<Object,Integer> map = new HashMap<>();
		map.put("status", 200);
		return JSON.toJSONString(map);

		
	}
	
}
